Skip to contentSkip to conversation

Custom variable value: (OVERRIDES?)

DISCUSSION Mauro Ziliani 3 participants 3 messages Apr 2, 2020 – Apr 5, 2020

lore
Share & tools
lore
#0 lore raw

Hi all.

I don't understand how can I change a the value of a variable inside a .bb file

I do this work

if MYVAR is empty I need to install default.txt in /etc

if MYVAR contains "white" i need to install white.txt in /etc

So I extend myreciped.bb with this file

myrecipe.bbappend

MYVAR = "default.txt"

MYVAR_white = "white.txt"

do_install_append() {

    install -m 0755 -d ${D}/etc

    install -m 0644 ${MYVAR}    ${D}/etc/value

}

In conf/local.conf I put

MYVAR_pn-myrecipe = "white"

But nothing works as I expect.

Where is my mistakes?

Best regards,

  MZ

#1 lore raw

Hi Mauro,

I assume that you are working with poky/meta layer.
You can use conditional function from oe.utils library like this:

YOUR_VAR = "${@oe.utils.conditional("VAR_NAME", "compare_value", "value_if_true", "value_if_false", d)}"

myrecipe.bbappend:
FILE_NAME = "${@oe.utils.conditional("MY_VAR", "white", "white.txt", "default.txt", d)}" do_install_append() {
install -m 0644 ${FILE_NAME} ${D}/etc/value
}

local.conf:
MY_VAR = "white"

Another way is using in-line python conditional statement:
FILE_NAME = "${@'white.txt' if 'white' in d.getVar('MY_VAR') else 'default.txt'}"

If you want more than two values, consider using variable flag:
https://www.yoctoproject.org/docs/latest/bitbake-user-manual/bitbake-user-manual.html#variable-flag-syntax

Regards,
DD

#2 lore raw
In reply to Mauro Ziliani
Quoted 29 lines · Mauro Ziliani

I don't understand how can I change a the value of a variable inside a .bb file

I do this work

if MYVAR is empty I need to install default.txt in /etc

if MYVAR contains "white" i need to install white.txt in /etc

So I extend myreciped.bb with this file

myrecipe.bbappend

MYVAR = "default.txt"

MYVAR_white = "white.txt"

do_install_append() {

     install -m 0755 -d ${D}/etc

     install -m 0644 ${MYVAR}    ${D}/etc/value

}

Quoted 8 lines

In conf/local.conf I put

MYVAR_pn-myrecipe = "white"

But nothing works as I expect.

Where is my mistakes?

You're mixing up a couple of concepts. In local.conf you could put:

MYVAR_pn-myrecipe = "white.txt"

which would force the value of MYVAR to be "white.txt" in myrecipe.

- or -

OVERRIDES_append_pn-myrecipe = ":white"

which adds "white" as an extra override for myrecipe, which would then means:

MYVAR_white = "white.txt"
becomes
MYVAR = "white.txt"

Hope that helps explain things!

Cheers,

Richard